package com.yanggu.scala.chapater12.object2

//模式匹配-对象匹配
object MathObjectDemo01 {

  def main(args: Array[String]): Unit = {
    //case中对象的unapply方法(对象提取器)返回Some集合则为匹配成功
    //返货none集合表示返回失败
    //匹配对象的用途：提取出对象的字段。用于后续的逻辑
    val number: Double = 36.0
    number match {
      case Square(n) => println(n)
      case _ => println("nothing matched")
    }
  }

}
object Square {

  def apply(z: Double): Double = z * z

  def unapply(z: Double): Option[Double] = Some(math.sqrt(z))
}

class Square(var z: Double){

}